package services;
import java.util.*;
import dao.*;
import dao.daoimpl.*;
import model.*;

public class Command {
	//添加用户操作
	public void add_Member(String userName, String userAddress, String userCarrer) {
		User user = new User(userName,userAddress,userCarrer);
		UserDao userdao = new UserDaoImpl();
		int userId = userdao.insertUser(user);
		//userId为-1代表用户已经存在
		if(userId==-1)
			System.out.println(user.getUserName()+" is existed");	
		else
			System.out.println("OK，"+user.getUserName()+"'s member id is "+ userId);	
		
	}
	//添加卡操作
	public void add_Card(String userName, int cardType,int count) {
			UserCardDao ucd = new UserCardDaoImpl();
			UserDao ud = new UserDaoImpl();
			User user = ud.selectUserByName(userName);
			//如果通过姓名找不到User，报错
			if(user==null){
				System.out.println("Error:userNameNotFound!");
				return;
			}
			int userId = user.getUserId();
			UserCard uc = new UserCard(userId, cardType);
			int insertcount = ucd.insertUserCard(uc,count);//插入数量，为-1代表续费现有卡片
			if (insertcount == -1) {
				if(cardType==2)
					System.out.println("OK，a New 次卡 with "+count+" times added to " + userName);
				else if(cardType==1)
					System.out.println("OK，a New 年卡 added to " + userName + "("+userId+")");
			}

		
			
	}
	public void add_Card(String userName, int cardType) {
		//添加年卡信息可不用填写count，故函数重载
		this.add_Card(userName, cardType, 0);
	}


}
